﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InstrumentCheck.Module;
using InstrumentCheck.BLL;

namespace InstrumentCheck.WebAppUI
{
    public partial class OriginalBox : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                User user = Session["UserInfo"] as User;
                List<ApplyForm> list = OriginalBox_bll.GetOriginalBox(user.EmpNO);
                ViewState["list"] = list;
                gv.DataSource = list;
                gv.DataBind();
            }
        }

        protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
                e.Row.Cells[0].Visible = false;

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ApplyForm form = e.Row.DataItem as ApplyForm;
                e.Row.Cells[1].Text = "<a href='" + this.PageURL() + "/CorrectItem.aspx?ID=" + form.FormID + "'>" + form.FormNO.ToString("0000000000") + "</a>";
                User applicant = form.Applicant;
                Item item = form.Item;

                e.Row.Cells[3].Text = applicant.EmpChineseName;
                e.Row.Cells[4].Text = item.AssetNO;
                e.Row.Cells[5].Text = item.ChiName;
                e.Row.Cells[6].Text = item.Spec;
                e.Row.Cells[7].Text = item.ModelNO;

                switch (form.FormStatus)
                {
                    case FormStatus.Agree:
                        e.Row.Cells[8].Text = "同意";
                        break;
                    case FormStatus.Disagree:
                        e.Row.Cells[8].Text = "不同意";
                        break;
                    case FormStatus.Processing:
                        e.Row.Cells[8].Text = "簽核中";
                        break;
                    case FormStatus.WithDraw:
                        e.Row.Cells[8].Text = "已抽單";
                        break;
                }
            }
        }

        protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gv.PageIndex = e.NewPageIndex;
            List<ApplyForm> list = ViewState["list"] as List<ApplyForm>;
            gv.DataSource = list;
            gv.DataBind();
        }
    }
}
